//
//  spriteDescription.m
//  cliptest
//
//  Created by James Tong on 31/05/2010.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "spriteLayer.h"


@implementation spriteLayer
- (void) loadSpriteWithDescriptionFile : (char *)fname {
	
	NSString * path = [[NSBundle mainBundle] pathForResource:  @"sprite" ofType: @"def"];

/*	if (path) {  
		NSString *myText = [NSString stringWithContentsOfFile:path];  
		if (myText) {  
			NSLog(myText);  
		}  
	} 
*/
 	fp = fopen([path cStringUsingEncoding:1],"r");

	if (fp == NULL) {
		NSLog(@"fail");
		return;
	}
	
	while (1) {
		if (fgets(buf, 512, fp)==NULL) {
			break;
			return;
		}
		
		[self parseDescription : buf];
/*		char *tmp = strtok (buf,", ");
		while (tmp != NULL)
		{
			printf ("%d\n",atoi(tmp));
			tmp = strtok (NULL, ", ");
		}
*/
	}

	fclose(fp);
	
}

- (void) parseDescription : (char *)s {
	char *tmp = strtok(s, ", \n");
	if (tmp == NULL)
		return;
	
	if (!strcmp("tilesize",tmp)) {		// 第一個token是command
		printf("command: %s\n",tmp);
		tmp = strtok(NULL, ", \n");
		_tileWidth = atoi(tmp);
		printf("%d\n",_tileWidth);
		tmp = strtok(NULL, ", \n");
		_tileHeight = atoi(tmp);
		printf("%d\n",_tileHeight);
/*		while (tmp!=NULL) {
			printf("%d\n",atoi(tmp));
			tmp = strtok(NULL, ", \n");
		}
*/	}
}
@end
